package com.qf.controller.admin;

import com.qf.entity.User;
import com.qf.service.OrderService;
import com.qf.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wgy
 * @version V1.0
 * @project gp12_xiaomi
 * @package ${PACKAGE_NAME}
 * @description: ${TODO}
 * @date 2022/6/28 10:54
 */
@WebServlet(name = "SendGoodsServlet",urlPatterns = "/ ")
public class SendGoodsServlet extends HttpServlet {
    private OrderService orderService;

    @Autowired
    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1判断是否登录 admin
        User admin= (User) request.getSession().getAttribute("admin");
        if(admin==null){
            response.sendRedirect(request.getContextPath()+"/admin/login.jsp");
            return;
        }
        //2获取参数
        String oid = request.getParameter("oid");
        if(StringUtils.isEmpty(oid)){
            return;
        }

        //4调用方法
        try {
            orderService.updateStatus(oid, "3");
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect(request.getContextPath()+"/getAllOrder");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
